package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Employee;
import cn.wolfcode.qo.JsonResult;
import cn.wolfcode.service.IEmployeeService;
import cn.wolfcode.service.IPermissionService;
import cn.wolfcode.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class LoginControllerxxxxx {
   /* @Autowired
    private IEmployeeService employeeService;

    @Autowired
    private IPermissionService permissionService;

    @RequestMapping("/login")
    @ResponseBody
    public JsonResult login(String username, String password, HttpSession session) {
        try {
            Employee employee = employeeService.login(username, password);
            //成功返回
            //把当前登录的员工 放到session中
            //session.setAttribute(UserContext.USER_IN_SESSION, employee);

            UserContext.setCurrentUser(employee);

            //判断是否 超级管理员 不是  就需要查询
            if (!employee.isAdmin()) {
                List<String> expressions = permissionService.selectExpressionByEmpId(employee.getId());
                //设进 session
                //session.setAttribute(UserContext.EXPRESSION_IN_SESSION, expressions);
                UserContext.setExpression(expressions);
            }


            return new JsonResult(true, "11");


        } catch (Exception e) {
            e.printStackTrace();
            //失败 接收抛出的异常 并输出其的 报错 信息   也是可以直接在这里 加信息 写死了 , 但是不要
            return new JsonResult(false, e.getMessage());
        }
    }

    @RequestMapping("/logout")
    //@ResponseBody  不用返回消息呀
    public String logout(HttpSession session) {
        session.invalidate();
        return "redirect:/login.html";
    }*/
}
